const promisic = function (func) {
  return function (params = {}) {
    return new Promise((resolve, reject) => {
      const args = Object.assign(params, {
        success: (res) => {
          resolve(res);
        },
        fail: (error) => {
          reject(error);
        }
      });
      func(args);
    });
  };
};
const formatSecond = function (value) {
  let secondTime = parseInt(value)
  let minuteTime = 0
  let hourTime = 0
  if(secondTime > 60) {
    minuteTime = parseInt(secondTime / 60);
    secondTime = parseInt(secondTime % 60);
    if(minuteTime > 60) {
      hourTime = parseInt(minuteTime / 60);
      minuteTime = parseInt(minuteTime % 60);
    }
  }
  let result = "" + parseInt(secondTime) + "秒"
  if(minuteTime > 0) {
    result = "" + parseInt(minuteTime) + "分" + result;
  }
  if(hourTime > 0) {
    result = "" + parseInt(hourTime) + "小时" + result;
  }
  return result;
}
const SplitFormatSecond = function (value) {
  let secondTime = parseInt(value)
  let minuteTime = 0
  let hourTime = 0
  if(secondTime > 60) {
    minuteTime = parseInt(secondTime / 60);
    secondTime = parseInt(secondTime % 60);
    if(minuteTime > 60) {
      hourTime = parseInt(minuteTime / 60);
      minuteTime = parseInt(minuteTime % 60);
    }
  }
  return {
    second: parseInt(secondTime),
    minute: parseInt(minuteTime),
    hour: parseInt(hourTime)
  };
}

export {
  promisic,
  formatSecond,
  SplitFormatSecond
}
